/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package serverv2_0;
import java.io.* ;
import java.net.* ;
import java.util.* ;
import java.util.Timer;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

/**
 *
 * @author suhui
 */
class Server {
    static int seconds = 60*1000;
    static int delay = 30*1000;
    static Timer pingtime ;
    static players playerlist = new players();

    static class pingtask extends TimerTask
    {
        public void run()
        {
            playerlist.pingall();
        }
    }

    public static void main(String args[]) throws Exception{
        pingtime = new Timer();
        pingtime.scheduleAtFixedRate(new pingtask(),delay,seconds);
        
        int port = 5000;
        //players playerlist = new players();
        ServerSocket socket = new ServerSocket(port);
       
        while (true) {
            Socket connection = socket.accept();
            TCPReceive packet = new TCPReceive(connection, playerlist);
            // Create a new thread to process the request.
	    Thread thread = new Thread(packet);
            //playerlist.addnew("abc", "123" , socket.getInetAddress(), socket.getLocalPort() );
	    // Start the thread.
	    thread.start();

        }

    }

}



